<template>
  <div>
    <form action="" @submit.prevent="login" v-model="form">
      <p>用户名: <input type="text" v-model="form.mobile"></p>
      <p>密码: <input type="text" v-model="form.password"></p>
      <button type="submit">登录</button>
    </form>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      form: {}
    }
  },
  methods: {
    login() {
      this.axios.post('user/login/', this.form)
        .then(res => {
          if (res.data.code == 200) {
            localStorage.getItem('userid', res.data.userid)
            this.$router.push({'path': '/glist'})
          } else if (res.data.code == 10010) {
            this.$router.push({'path': ''})
          } else {
            alert('请输入正确的密码')
          }
        })
    }
  },
  mounted() {
  }
}
</script>

<style scoped>

</style>
